/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef PJIT_ASM_X86_H_
#define PJIT_ASM_X86_H_

#include "pjit_x86.h"
#include <ostream>

#if PICOJIT_TARGET == 1 || PICOJIT_TARGET == 2

namespace pjit{

class pjit_asm_x86 {

public:
	// CONSTRUCTOR
	pjit_asm_x86( pjit_block &block, uint32 bytes );
	// MAIN INTERFACE
	pjit_asm_x86 &mov_reg32_to_reg32( uint32 reg32a, uint32 reg32b );
	pjit_asm_x86 &mov_imm32_to_reg32( uint32 reg32, uint32 imm32, uint32 pmode );
	pjit_asm_x86 &add_imm32_to_reg32( uint32 reg32, uint32 imm32, uint32 pmode );
	pjit_asm_x86 &sub_imm32_to_reg32( uint32 reg32, uint32 imm32, uint32 pmode);
	pjit_asm_x86 &push_imm32( uint32 imm32, uint32 pmode );
	pjit_asm_x86 &push_reg32( uint32 reg32 );
	pjit_asm_x86 &far_call_reg32( uint32 reg32 );
	pjit_asm_x86 &leave( void );
	pjit_asm_x86 &ret( void );

public:
	// GETTERS
	pjit_block &block( void );

protected:
	// HELPING FUNCTIONS (SPECIAL BYTES)
	uint8 help_modrm( uint32 mod, uint32 reg_op, uint32 rm );
	uint8 help_sib( uint32 ss, uint32 reg_op, uint32 index );
	// HELPING FUNCTIONS (PRINT)
	std::string  help_print_imm32( uint32 imm32, uint32 pmode );
	std::ostream &help_print_offset( void );
	std::ostream &help_print_format( void );

protected:
	// INNER PROPERTIES
	pjit_block *_block;

};

};

#endif // PICOJIT_TARGET == 1 || PICOJIT_TARGET == 2

#endif // PJIT_ASM_X86_H_
